using UnityEngine;
using UnityEngine.UI;

namespace Voodoo.Meta.RVModules
{
	public class Chest : MonoBehaviour
	{
		public bool isOpen;

		public ChestVisual chestVisual;

		public GameObject chestHidderBig;

		public GameObject chestHidderText;

		private ChestHidder _chestHidder;

		private Button _button;

		private ChestRoomView _chestRoomView;

		private RewardInfo _content;

		public void SetUp(float delay, ChestRoomView chestRoomView)
		{
			if (_chestRoomView == null)
			{
				_chestRoomView = chestRoomView;
			}
			if (_button == null)
			{
				_button = GetComponent<Button>();
			}
			_button.onClick.RemoveAllListeners();
			_button.onClick.AddListener(OnClick);
			chestVisual.SetUp(delay);
			isOpen = false;
		}

		private void OnClick()
		{
			if (!isOpen && _chestRoomView.keyArea.IsAKeyAvailable())
			{
				isOpen = true;
				_chestRoomView.UseAKey(this);
			}
		}

		public void OpenChest()
		{
			_button.onClick.RemoveListener(OnClick);
			chestVisual.Open();
		}

		public void SetUpRewardVisual(RewardInfo parameters)
		{
			_content = parameters;
		}

		public void ChestOpened()
		{
			_chestRoomView.OpenChest(this);
			ShowContent(_content);
		}

		public void ShowContent(RewardInfo parameters)
		{
			GameObject gameObject = Object.Instantiate((parameters.amount < 2) ? chestHidderBig : chestHidderText, base.transform);
			_chestHidder = gameObject.GetComponent<ChestHidder>();
			_chestHidder.Set(parameters);
			_chestHidder.Open();
		}

		public void Clean()
		{
			chestVisual.Clean();
		}
	}
}
